package com.asialjim.wechat.database;

import com.asialjim.wechat.core.bean.WeChatBean;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.io.Serializable;
import java.util.*;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: DataBaseService ]</i></h2><strong>
 * <p> 通用数据库表操作服务
 * <p> 操作对象：单数据库表的增删改查服务</p>
 * <h3>条件</h3>
 * <ol>
 *     <li>数据库服务组件需要被注解 {@link org.springframework.stereotype.Repository} 标注，且需要继承基础接口 {@link BaseMapper}</li>
 *     <li>被操作的数据库表需要提供数据库表实体，且该表实体需要被注解 {@link TableName} 标注以指定被操作的数据库表名</li>
 * </ol>
 * <p>如果需要使用自定义Mapper接口中的自定义方法，需要使用 {@link #selectMapper(Class)} 方法取出目标组件，并强转为目标组件</p>
 * <pre>{@code
 *       @Autowired private DataBaseService service;
 *       public void test(){
 *           BaseMapper<AssistantActivityDB> assistantActivityDBBaseMapper = service.selectMapper(AssistantActivityDB.class);
 *           // 此处强转需要确保获取到的目标组件确为要强转成的目标组件，否则将会报错
 *           AssistantActivityDao dao = (AssistantActivityDao) assistantActivityDBBaseMapper;
 *           List<AssistantActivityDB> assistantActivityDBS = dao.queryMaxAllowTimeActivity();
 *       }
 *     }
 * </pre>
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/1/28   &nbsp;&nbsp; JDK 8
 */
@SuppressWarnings({"all"})
public interface DataBaseService{
    String BEAN_NAME = "dataBaseService";

    Map<String,List<DataBaseTableInfo>> allTables();

    <T> IPage<T> selectPage(IPage<T> page,T condition);


    Class<?> classByTableName(String tableName);

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: mapperTableNames ]</i></h3>
     * 获取所有此接口支持的数据库表名称
     * @return {@link List< String> 数据库表列表}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/17 15:26
     */
    List<String> mapperTableNames();

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 获取数据库表操作
     * <p>传入要操作的数据库表实体，然后获取到对应的数据库表操作BaseMapper组件</p>
     * <p>需要对应的数据库表操作组件已经继承了{@code BaseMapper}接口，并且被注解{@code Repository}标注</p>
     * @param targetClass {@link Class<T> 要操作的数据库表实体的类}
     * @return {@link BaseMapper<T> 目标数据库表操作服务组件}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 9:20
     */
    <T> BaseMapper<T> selectMapper(Class<T> targetClass);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库实体实例条件查询数据库记录
     * @param condition {@link T 数据库表实体条件}
     * @param <T> 数据库表实体类型
     * @return {@link T 查询结果}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/27 16:09
     */
    <T> T selectOne(T condition);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据主键和数据库表实体类查询数据库实体
     * @param tableClass {@link Class<T> 数据库表实体类}
     * @param id {@link Serializable 主键}
     * @return {@link T 数据库实体}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:45
     */
    <T> T selectById(Class<T> tableClass,Serializable id);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据主键列表批量查询数据库实体列表
     * @param tableClass {@link Class<T> 数据库表实体类}
     * @param idList {@link Collection<Serializable> 主键列表}
     * @return {@link List<T> 数据库实体列表}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:47
     */
    <T> List<T> selectBatchIds(Class<T> tableClass, Collection<? extends Serializable> idList);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据Map查询数据库实体列表
     * @param tableClass {@link Class<T> 数据库实体类}
     * @param columnMap {@link Map<String,Object> 查询条件}
     * @return {@link List<T> 数据库实体列表}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:48
     */
    <T> List<T> selectByMap(Class<T> tableClass,Map<String, Object> columnMap);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库实体条件计数
     * @param conditionEntity {@link T 数据库条件}
     * @return {@link Integer 计数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:49
     */
    <T> Integer selectCount(T conditionEntity);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库实体条件查询map列表
     * @param conditionEntity {@link T 数据库实体条件}
     * @return {@link List< Map< String, Object>> 数据库列表}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:50
     */
    <T> List<Map<String, Object>> selectMaps(T conditionEntity);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库条件查询数据库实体列表
     * @param condition {@link T 数据库条件实体}
     * @return {@link List<T> 数据库实体列表}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:51
     */
    <T> List<T> selectList(T condition);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 向数据库插入新的数据库实体
     * @param entity {@link T 数据库表实体}
     * @return {@link Integer 插入结果}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:52
     */
    <T> int insert(T entity);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库实体条件删除数据
     * @param entity {@link T 数据库实体条件}
     * @return {@link Integer 删除结果影响记录条数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:53
     */
    <T> int delete(T entity);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据主键和数据库表实体类删除数据库表记录
     * @param tableClass {@link Class<T> 数据库表实体类}
     * @param id {@link Serializable 主键}
     * @return {@link Integer 影响数据库记录条数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:54
     */
    <T> int deleteById(Class<T> tableClass,Serializable id);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据条件map数据库表记录
     * @param tableClass {@link Class<T> 数据库表实体类}
     * @param columnMap {@link Map 删除条件}
     * @return {@link Integer 影响记录条数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:55
     */
    <T> int deleteByMap(Class<T> tableClass,Map<String, Object> columnMap);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据主键和数据库表实体类批量删除数据库表记录
     * @param tableClass {@link Class<T> 数据库表实体类}
     * @param idList {@link Collection 主键列表}
     * @return {@link Integer 影响数据库记录条数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:56
     */
    <T> int deleteBatchIds(Class<T> tableClass, Collection<? extends Serializable> idList);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库实体条件更新数据库表
     * @param updateToEntity {@link T 要更新成的数据库实体记录}
     * @param updateCondition {@link T 更新条件数据库表实体}
     * @return {@link Integer 影响条数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:58
     */
    <T> int update(T updateToEntity, T updateCondition);

    /**
     * <h4>METHOD DESCRIPTION</h4>
     * 根据数据库表实体主键更新数据库表记录
     * @param entity {@link T 数据库表目标实体记录}
     * @return {@link Integer 影响条数}
     * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
     * @since 2021/1/28 11:59
     */
    <T> int updateById(T entity);
}